﻿using System;
using System.Windows.Forms;
using Styx.Common;

namespace FrostMage
{
    public partial class FrostMageGUI : Form
    {

        public FrostMageGUI()
        {
            InitializeComponent();
        }

        protected void FrostMageGUI_Load(object sender, EventArgs e)
        {
            try
            {
                toNyxMageSettings.Instance.Load();
            }
            catch (Exception ex)
            {
                Logging.Write(ex.ToString());
            }

            // AOE
            cb_UseAOE.Checked = toNyxMageSettings.Instance.EnableAOE;
            dud_enemyAmount.Value = new decimal(toNyxMageSettings.Instance.MinimumEnemiesAOE);
            cb_FlameStrike.Checked = toNyxMageSettings.Instance.UseFlameStrike;
            cb_Blizzard.Checked = toNyxMageSettings.Instance.UseBlizzard;

            // DEF SHIT PART
            cb_UseIceBarrier.Checked = toNyxMageSettings.Instance.UseIceBarrier;
            cb_UseIceBlock.Checked = toNyxMageSettings.Instance.UseIceBlock;
            nup_IceBlockHP.Value = new decimal(toNyxMageSettings.Instance.IceBlockHP);
            cb_Healthstone.Checked = toNyxMageSettings.Instance.UseHealthStone;
            nup_healthstonepc.Value = new decimal(toNyxMageSettings.Instance.HealthStoneHP);

            // UTILITY PART
            cb_conjureFood.Checked = toNyxMageSettings.Instance.ConjureFood;
            cb_UseManaGem.Checked = toNyxMageSettings.Instance.UseManaGem;
            nup_ManaGemMP.Value = new decimal(toNyxMageSettings.Instance.ManaGemMP);
            cb_FaceTarget.Checked = toNyxMageSettings.Instance.FaceTarget;
            cb_UsePolyMorphOnFocus.Checked = toNyxMageSettings.Instance.UsePolymorphOnFocus;
            cb_disableOnBoss.Checked = toNyxMageSettings.Instance.DisablePolymorphOnBosses;
            cb_decurse.Checked = toNyxMageSettings.Instance.UseDecurse;

            // TALENT PART
            cb_UseEvocation.Checked = toNyxMageSettings.Instance.UseEvocation;
            rb_EvocKeep.Checked = toNyxMageSettings.Instance.KeepEvocationBuff;
            rb_EvocThreshold.Checked = toNyxMageSettings.Instance.EvocBelowThreshold;
            nup_EvocBelowThreshold.Value = new decimal(toNyxMageSettings.Instance.EvocThresholdMP);
            cb_RoP.Checked = toNyxMageSettings.Instance.UseRoP;

            // HOTKEYS PART
            cb_UseHK.Checked = toNyxMageSettings.Instance.EnableHotKeys;
            combo_Modifier.SelectedItem = toNyxMageSettings.Instance.HotKeyModifier;
            combo_AoE.SelectedItem = toNyxMageSettings.Instance.AoEHotKey;

        }

        #region AOESettings
      
            private void cb_UseAOE_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.EnableAOE = cb_UseAOE.Checked;
            }

            private void dud_enemyAmount_ValueChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.MinimumEnemiesAOE = (int) dud_enemyAmount.Value;
            }

            private void cb_FlameStrike_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseFlameStrike = cb_FlameStrike.Checked;
            }

            private void cb_Blizzard_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseBlizzard = cb_Blizzard.Checked;
            }

        #endregion

        #region DefensiveStuff

            private void cb_UseIceBarrier_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseIceBarrier = cb_UseIceBarrier.Checked;
            }

            private void cb_UseIceBlock_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseIceBlock = cb_UseIceBlock.Checked;
            }

            private void nup_IceBlockHP_ValueChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.IceBlockHP = (int) nup_IceBlockHP.Value;
            }

            private void cb_Healthstone_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseHealthStone = cb_Healthstone.Checked;
            }

            private void nup_healthstonepc_ValueChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.HealthStoneHP = (int) nup_healthstonepc.Value;
            }

        #endregion

        #region UtilityStuff

            private void cb_conjureFood_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.ConjureFood = cb_conjureFood.Checked;
            }

            private void cb_UsePolyMorphOnFocus_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UsePolymorphOnFocus = cb_UsePolyMorphOnFocus.Checked;
                cb_disableOnBoss.Enabled = cb_UsePolyMorphOnFocus.Checked;
            }

            private void cb_disableOnBoss_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.DisablePolymorphOnBosses = cb_disableOnBoss.Checked;
            }

            private void cb_UseManaGem_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseManaGem = cb_UseManaGem.Checked;
            }

            private void nup_ManaGemMP_ValueChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.ManaGemMP = (int)nup_ManaGemMP.Value;
            }

            private void cb_FaceTarget_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.FaceTarget = cb_FaceTarget.Checked;
            }

            private void cb_decurse_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseDecurse = cb_decurse.Checked;
            }

        #endregion

        #region TalentsStuff

            private void cb_UseEvocation_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseEvocation = cb_UseEvocation.Checked;
                gb_evoc_conditions.Enabled = cb_UseEvocation.Checked;
            }

            private void rb_EvocKeep_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.KeepEvocationBuff = rb_EvocKeep.Checked;
            }

            private void rb_EvocThreshold_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.EvocBelowThreshold = rb_EvocThreshold.Checked;
            }

            private void nup_EvocBelowThreshold_ValueChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.EvocThresholdMP = (int)nup_EvocBelowThreshold.Value;
            }

            private void cb_RoP_CheckedChanged(object sender, EventArgs e)
            {
                toNyxMageSettings.Instance.UseRoP = cb_RoP.Checked;
            }

        #endregion

        #region HotkeyStuff

        private void cb_UseHK_CheckedChanged(object sender, EventArgs e)
        {
            toNyxMageSettings.Instance.EnableHotKeys = cb_UseHK.Checked;
            gb_HKSettings.Enabled = cb_UseHK.Checked;       
        }

        private void combo_Modifier_SelectedIndexChanged(object sender, EventArgs e)
        {
            toNyxMageSettings.Instance.HotKeyModifier = (string) combo_Modifier.SelectedItem;
        }

        private void combo_AoE_SelectedIndexChanged(object sender, EventArgs e)
        {
            toNyxMageSettings.Instance.AoEHotKey = (string) combo_AoE.SelectedItem;
        }

        #endregion

            private void bt_SaveSettings_Click(object sender, EventArgs e)
        {
            toNyxMageSettings.Instance.Save();
            Logging.Write("Settings Saved");
            toNyxMage.Hotkeys_Init();
            Close();
        }

    }
}
